using Budget.Core.Data;
using NHibernate;

namespace Budget.Data
{
    public class NHibernateTransaction : INHibernateTransaction
    {
        private readonly ITransaction transaction;
        
        public NHibernateTransaction(ISession session)
        {
            this.Session = session;
            this.transaction = this.Session.Transaction;
        }

        protected ISession Session { get; set; }

        protected ITransaction Transaction
        {
            get
            {
                return this.transaction;
            }
        }

        public void Begin()
        {
            this.Transaction.Begin();
        }

        public void Commit()
        {
            this.Transaction.Commit();
        }

        public void Rollback()
        {
            this.Transaction.Rollback();
        }

        public bool IsActive
        {
            get
            {
                return this.Transaction.IsActive;
            }
        }

        public virtual void Dispose()
        {
            this.Transaction.Dispose();
        }
    }
}